//
//  newFeatureController.m
//  Weibo2
//
//  Created by Gate on 15/11/10.
//  Copyright © 2015年 Gate. All rights reserved.
//
#import "TabbarViewController.h"
#import "NewFeatureController.h"
@interface NewFeatureController()<UIScrollViewDelegate>
@property (nonatomic,strong) UIPageControl *pageControl;
@end
@implementation NewFeatureController
- (void)viewDidLoad{
    [super viewDidLoad];
    //1.添加scrollview
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    //2.添加图片
    CGFloat imageW = scrollView.frame.size.width;
    CGFloat imageH = scrollView.frame.size.height;
    for (int index = 0; index < 3;index++) {
        NSString *name = [NSString stringWithFormat:@"new_feature_%d",index + 1];
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:name];
        CGFloat imageX = index *imageW;
        imageView.frame = CGRectMake(imageX, 0, imageW, imageH);
        [scrollView addSubview:imageView];
        if (index == 2) {
            [self setLastImageView:imageView];
        }
    }
    //3.设置滚动的内容尺寸
    scrollView.contentSize = CGSizeMake(3 *imageW, 0);
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
//    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_background"]];
    //4.pageControl
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = 3;
    pageControl.center = CGPointMake(self.view.frame.size.width*0.5, self.view.frame.size.height - 100);
    pageControl.userInteractionEnabled = NO;
    pageControl.bounds = CGRectMake(0, 0, 100, 30);
    pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    pageControl.pageIndicatorTintColor = [UIColor redColor];
    [self.view addSubview:pageControl];
    self.pageControl = pageControl;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //1.取出水平方向的滚动值
    CGFloat offSetX = scrollView.contentOffset.x;
    double pageDouble = offSetX / scrollView.frame.size.width;
    int pageInt = (int)(pageDouble + 0.5);
    self.pageControl.currentPage = pageInt;
}
- (void)setLastImageView:(UIImageView *)imageView{
    imageView.userInteractionEnabled = YES;
    UIButton *button = [[UIButton alloc] init];
    [button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor greenColor]];
    [button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [button setTitle:@"快体验" forState:UIControlStateNormal];
    
    
    button.center = CGPointMake(imageView.frame.size.width * 0.5, imageView.frame.size.height * 0.6);
    button.bounds = (CGRect){CGPointZero,button.currentBackgroundImage.size};
    [button addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:button];
    //设置checkBox
    UIButton *checkBox = [[UIButton alloc] init];
    checkBox.selected = YES;
    [checkBox setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [checkBox setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [checkBox setTitle:@" 分享至微博" forState:UIControlStateNormal];
    checkBox.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    checkBox.bounds = CGRectMake(0, 0, 200, 30);
    checkBox.center = CGPointMake(imageView.frame.size.width * 0.5, imageView.frame.size.height * 0.5);
    [checkBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [checkBox addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:checkBox];
    

}
- (void)start{
    self.view.window.rootViewController = [[TabbarViewController alloc] init];
    
}
- (void)share:(UIButton *)checkBox{
    checkBox.selected = !checkBox.isSelected;
//    checkbox.selected = !checkbox.isSelected;
    
}
@end
